import Immutable from 'immutable';

import { UPDATE_VIEWPORT_REDUX } from './actionTypes';
import preloadedState from '../../preloadedState';

const defaultViewport = preloadedState.get('viewport');

function reducer (state = defaultViewport, action) {
    const { type, payload } = action;
    let newState;

    switch (type) {
        case UPDATE_VIEWPORT_REDUX:
            newState = state.merge(Immutable.fromJS(payload));
            return newState;
        default:
            return state;
    }
}

export default reducer;